﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UnFixedWordLoadSet.aspx.aspx.cs" Inherits="Basic4Net.OAWeb.Module_Base.UnFixedWordLoadSet" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>岗位不固定工作量</title>
    <link type="text/css" rel="stylesheet" href="../App_Themes/ui-lightness/main.css" />
    <script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="../Scripts/Common.js"></script>  
  
   <script>

       var re = /^[0-9]+.?[0-9]*$/; //验证正数
       var delArr = new Array();



       //关闭遮罩层
       function CloseMask(formId) {
           ClosePopForm(formId, true);
           hideMask();
       }
       //---------------------------------------------------------------------------------其他 



       //编辑状态
       function modi(obj) {

           if (obj.readOnly == true) {
               //   obj.parentElement.style.textAlign = 'center';
               obj.style.textAlign = 'left';
               obj.style.border = 'solid #a5a5a5 1px;';
               obj.readOnly = false;
               obj.select();
               updateActivate = 1;
           }
       }


       //非编辑状态
       function unModi(obj, align) {
           if (obj.readOnly == false) {
               obj.parentElement.style.textAlign = align;
               obj.style.textAlign = align;
               obj.style.border = 'solid #ffffff 1px;';
               obj.readOnly = true;
               updateActivate = 0;
           }
       }


       //选中行高亮
       function SetHightLight(obj) {
           if (obj != null)
               obj.style.backgroundColor = "#fffccf";

           var table = document.getElementById('table');
           for (var i = 0; i < table.rows.length; i++) {
               var row = table.rows[i];
               if (row != null && row.rowIndex != obj.rowIndex) {
                   row.style.backgroundColor = "#ffffff";
               }
           }
       }


       function FilterCount() {
           var value = event.srcElement.value;
           var table = document.getElementById('table');
           var rowIndex = event.srcElement.parentElement.parentElement.rowIndex;
           var row = table.rows[rowIndex];
           if (value == 1) {
               row.cells[2].all[0].style.display = "none";
               //    row.cells[3].all[0].style.display = "none"; 
           }
           else {
               row.cells[2].all[0].style.display = "block";
               //    row.cells[3].all[0].style.display  = "block"; 
           }
       }

       //------------------------------------------------------------------------------------添加
       //-----------弹出添加类型遮罩层
       function ShowAddWindow() {
           document.getElementById("txtTypeName").value = "";
           ShowPopForm("popTable", "formTitle", "添加类型");
           showMask();
           document.getElementById('txtTypeName').focus();
       }

       function AddRow() {
           var table = document.getElementById('table');
           document.getElementById('txtWorkName').value = ""; //清空分值名
           ShowPopForm("popTable", "formTitle", "添加");
           showMask();
       }

       function Add() {
           if (document.getElementById('table') != null) {
               var table = document.getElementById('table');
               var workName = document.getElementById('txtWorkName').value.Trim();
               var converNum = document.getElementById('txtConverNum').value.Trim();
               var acc = document.getElementById('chkAcc').checked == true ? 1 : 0;
               if (workName.length == 0) {
                   showNoticMsg('txtWorkName', '请先确定要添加的不固定工作量名', -120, 10);
                   return;
               }
               if (converNum.length == 0) {
                   showNoticMsg('txtConverNum', '请先确定要添加的折算节数', -120, 10);
                   return;
               }

//               //验证指标名是否重复 
//               if (ValidateItemName(workName)) {
//                   showNoticMsg('txtWorkName', '工作量名重复，请重新输入', -80, 10);
//                   return;
//               }
               PageMethods.ValidateItemName(workName, function (succ) {
                   if (succ > 0) {
                       showNoticMsg('txtWorkName', '不固定工作量名重复，请重新输入', -80, 10);
                       return;
                  }
                   else {
                       if (converNum != null && converNum.length > 0) {
                           if (converNum > 0) {
                               if (!re.test(converNum)) {
                                   showNoticMsg('txtConverNum', "非法输入！请输入数字(例:1,0.02)", -80, 10);
                                   document.getElementById('txtConverNum').focus();
                                   return;
                               }
                           }
                           else {
                               showNoticMsg("txtConverNum", "非法输入，请输入大于0的数字", -80, 10);
                               document.getElementById("txtConverNum").focus();
                               return;
                           }
                       }

                       PageMethods.Insert(workName, converNum, acc,function (succ) {
                           if (succ > 0) {
                               showMassgeBox("提示", "添加成功", 1, null);
                               CloseMask('popTable');
                               Bind();
                           }
                       }, function (err) {
                           showMassgeBox("提示", "添加失败", 1, null);
                       });
                   }
               }, function (err) {
                   showMassgeBox("提示", "验证失败1", 1, null);
               });
               
           }
       }

       //验证指标名是否重复
       function ValidateItemName(workName) {
           var bValidate = false;
           PageMethods.ValidateItemName(workName, function (succ) {
               if (succ > 0)
                   bValidate = true;
           }, function (err) {
               showMassgeBox("提示", "验证失败2", 1, null);
           });
           return bValidate;
       }

       //--------------------------------------------------------------------------------------验证及修改

       function UpdateInfo(row) {
           if (row != null) {
               var rid = row.itemid;
               var workName = "";
               var convertNum = "";
               if (row.cells[0].all != null && row.cells[0].all.length > 0) {
                   workName = row.cells[0].all[0].value;

//                   //验证指标名是否重复 
//                   if (ValidateItemName(workName)) {
//                       showNoticMsg('txtWorkName', '工作量名重复，请重新输入', -80, 10);
//                       return;
                   //                   }
                   if (row.cells[0].all[0].value != row.cells[0].all[0].oldvalue) {
                       PageMethods.ValidateItemName(workName, function (succ) {
                           if (succ > 0) {
                               showNoticMsg(row.cells[0].all[0].id, '不固定工作量名重复，请重新输入', -80, 10);
                               row.cells[0].all[0].value = row.cells[0].all[0].oldvalue;
                               return;
                           }
                           else {
                               if (row.cells[1].all != null && row.cells[1].all.length > 0) {
                                   convertNum = row.cells[1].all[0].value;
                               }
                               PageMethods.UpdateInfo(rid, workName, convertNum, function (succ) {
                                   if (succ > 0) {
                                       Bind();
                                   }
                               }, function (err) {
                                   showMassgeBox("提示", "验证失败3", 1, null);
                               });
                           }
                       }, function (err) {
                           showMassgeBox("提示", "验证失败4", 1, null);
                       });
                   }
                   else {
                       if (row.cells[1].all != null && row.cells[1].all.length > 0) { 
                           convertNum = row.cells[1].all[0].value;
                       }
                       PageMethods.UpdateInfo(rid, workName, convertNum, function (succ) {
                           if (succ > 0) {
                               Bind();
                           }
                       }, function (err) {
                           showMassgeBox("提示", "验证失败5", 1, null);
                       });
                   }
               } 
           }
       }

       function optionSettingScore(obj) {
           s = true;

           var id = obj.parentElement.parentElement.id;
           var value = obj.value;

           if (value.search(/^(-|\+)?\d+(\.\d+)?$/) == -1) {

               if (value.length > 0 && value.charAt(value.length - 1) == ".") {
                   value = value.substr(0, value.length - 1);
                   if (value.search(/^(-|\+)?\d+(\.\d+)?$/) == -1) {
                       obj.setAttribute("value", obj.getAttribute("oldvalue"));
                       return;
                   }
                   else {
                       if (CheckCh(value)) {
                           obj.setAttribute("value", value);
                           obj.setAttribute("oldvalue", value);
                       }
                       else {
                           obj.setAttribute("oldvalue", value);
                       }
                   }
               }
               else {
                   if (value.length == 0 || (/\D/.test(value))) {
                       obj.setAttribute("value", obj.getAttribute("oldvalue"));
                       return;
                   }
                   else {
                       obj.setAttribute("value", value);
                       obj.setAttribute("oldvalue", value);
                   }
               }
           }
           else {
               obj.setAttribute("oldvalue", value);
           }

           unModi(obj, 'right');
           UpdateInfo(obj.parentElement.parentElement);
       }

       function CheckCh(avalue) {
           for (n = 0; n < avalue.length; n++) {
               if (avalue[n] > 128)//   中文字符
               {
                   return false;
               }
           }
           return true;
       }

       function optionSettingProject(obj) {
           s = true;
           //var id = obj.parentElement.parentElement.id;
           var value = obj.value;

           if (value.length == 0) {
               obj.setAttribute("value", obj.getAttribute("oldvalue"));
               value = obj.value;
               return;
           }
           else {
               obj.value = value;
               value = obj.value;
           }

           unModi(obj, 'left');

           UpdateInfo(obj.parentElement.parentElement);
       }


       //----------------------------------------------------------------------------------------删除 
       //弹出删除窗口  
       function ShowDelWindow(row) {
           showConfirmBox("删除", "确定删除此职务?", DelPostInfo, row);
       }

       function DelPostInfo(row) {
           var table = document.getElementById('table');
           table.deleteRow(row.rowIndex);
           if (row.itemid != null) {
               PageMethods.DeleteByID(row.itemid, function (succ) {
                   if (succ > 0) {
                       showMassgeBox("提示", "删除成功", 1, null);
                       Bind();
                   }

               }, function (err) {
                   showMassgeBox("提示", "验证失败6", 1, null);
               });
           }
       }


       function Bind() {
           delArr = new Array();
           document.getElementById('btnItemBind').click();
       }

       function OptionAcc(obj) {
           var workId = obj.id;
           if(workId ==null || workId <0)
                return; 
           if (obj.checked) {
               showConfirmBox("提示", "确实将不固定工作量关联到学科系数的计算?", SetAccTrue, workId, Bind); 
           }
           else{
               showConfirmBox("提示", "确实取消不固定工作量与学科系数计算的关联?", SetAccFalse, workId, Bind);
           }
       }
       function SetAccTrue(workId) {
           PageMethods.SetAcc(workId, 1, function (succ) {
               if (succ > 0) {
                   showMassgeBox("提示", "设置成功", 1, null);
                   Bind();
               }
           }, function (err) {
               showMassgeBox("提示", "设置失败", 1, null);
           });
       }

       function SetAccFalse(workId){
           PageMethods.SetAcc(workId, 0, function (succ) {
               if (succ > 0) {
                   showMassgeBox("提示", "设置成功", 1, null);
                   Bind();
               }
           }, function (err) {
               showMassgeBox("提示", "设置失败", 1, null);
           });
       }

       </script>

</head>
<body>
      <div style="overflow-y: auto; overflow-x: none; height: 98%;">
        <form id="form1" runat="server">
            <div class="mainWarp">
                <div class="pageBody" style="height: 96%;">
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>  
                        
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                        <ul class="butList">
                            <li>
                                <input type="button" value="新增" class="commonBut" id="btnAddItem" onclick="AddRow();" />
                            </li>
                        </ul>  
                                
                        <div style="overflow-y: auto; overflow-x: none; height: 90%;">
                            <table id="table" class="useList" style="width: 50%">
                                <tr >
                                    <th style="text-align: left; padding-left: 5px;">
                                        分类名称</th>
                                    <th style="text-align: right; padding-right: 5px;">
                                        折算节数</th> 
                                    <th>是否参与学科系数计算</th>
                                    <th style="width: 10%">
                                        删除</th>
                                </tr>
                        <asp:Repeater ID="Repeater1" runat="server">    
                            <ItemTemplate> 
                                <tr itemid="<%# Eval("RID")%>"  onclick="SetHightLight(this);">
                                    <td>
                                        <input  onpaste="return false;"
                                        ondragenter="return false" maxlength="20" class="txtStyle" style='text-align: left;
                                        border-left: 0px; width: 98%; border-top: 0px; border-right: 0px; border-bottom: 0px;
                                        font-weight:inherit;color:#006f9f;
                                        font-style:inherit;
                                        font-size:12px; 
                                        font-family:'SimSun', Arial, Helvetica, sans-serif;'
                                        id="td<%# Eval("WorkName")%>" value="<%# Eval("WorkName")%>" oldvalue="<%# Eval("WorkName")%>"
                                        onfocusout="optionSettingProject(this)" onclick="modi(this)" readonly /> </td>
                                    <td style=" text-align:right; padding-right:5px;">
                                        <input onkeypress="return (event.keyCode>=48&&event.keyCode<=57)||event.keyCode==46" onpaste="return false;"
                                        ondragenter="return false" maxlength="4" class="txtStyle" style='text-align: right; display:block;
                                        border-left: 0px; width: 98%; border-top: 0px; border-right: 0px; border-bottom: 0px;
                                        font-weight:inherit;color:#006f9f;
                                        font-style:inherit;
                                        font-size:12px;
                                        font-family:'SimSun', Arial, Helvetica, sans-serif;'
                                        id="Text1" value="<%# Eval("ConvertNum")%>" oldvalue="<%# Eval("ConvertNum")%>"
                                        onfocusout="optionSettingScore(this)" onclick="modi(this)" readonly />
                                    </td>
                                    <td><input id="<%# Eval("RID")%>" type="checkbox" <%# (Eval("ACC")==null?0:(int)Eval("ACC"))==1?"checked":"" %>  onclick="OptionAcc(this);" /></td>
                                    <td><a><img src="../App_Themes/ui-lightness/images/delete_icon.gif" onclick="ShowDelWindow(this.parentElement.parentElement.parentElement);"/></a></td>
                                </tr> 
                            </ItemTemplate>
                            </asp:Repeater> 
                        </table>
                    </div>  
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnItemBind" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>

                <%--服务器端控件层--%>
                <div style="display:none;">
                    <asp:Button runat="server" ID="btnItemBind" onclick="btnItemBind_Click" />
                    <asp:TextBox runat="server" ID="txtHistoryId" />
                    <asp:TextBox runat="server" ID="txtTypeId" />
                </div>
                  
                     
                <%-- 添加固定工作量弹出层 --%>
                <div id="popTable" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                    <div class="title">
                        <span id="formTitle">添加</span> <a title="关闭" onclick="return CloseMask('popTable');">
                            关闭</a>
                    </div>
                    <table>
                        <tr><td style=" text-align:right">名称：</td><td><input type="text" id="txtWorkName" maxlength="20"/></td></tr>
                        <tr><td style=" text-align:right">折算节数：</td><td><input type="text" id="txtConverNum" maxlength="20"/></td></tr>
                        <tr><td style=" text-align:right">学科系数的计算：</td><td style=" text-align:left"><input type="checkbox" id="chkAcc"/></td></tr>
                        <tr>
                            <td colspan="2">
                                <input type="button" id="btnOK" value="确定"class="commonBut" onclick="Add();" />
                                <input type="button" id="btnCancel" value="取消" class="commonBut" onclick="return CloseMask('popTable');"/>
                            </td>
                        </tr>
                    </table>  
                </div>  

            </div>
        </form>
    </div>
</body>
</html>
